<?php
/*
  $Id: master_listing.php

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce
  
  Master Products MS2  - JOHNSON - 05/07/2003 matti@suomedia.com
 
  Copyright (c) 2003 Suomedia - Dynamic Content Management

  Released under the GNU General Public License
    
*/

  $listing_split = new splitPageResults($master_sql, MAX_DISPLAY_SEARCH_RESULTS, 'products_master');
   


  if ( ($listing_split->number_of_rows > 0) && ( (MASTER_PREV_NEXT_BAR_LOCATION == '1') || (MASTER_PREV_NEXT_BAR_LOCATION == '3') ) ) {


?>


<table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr>
    <td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
    <td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
  </tr>
</table>
<?php
  }


  
  $list_box_contents = array();

  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
      case 'MASTER_LIST_MODEL':
        $lc_text = TABLE_HEADING_MODEL;
        $lc_align = '';
        break;
      case 'MASTER_LIST_NAME':
        $lc_text = TABLE_HEADING_PRODUCTS;
        $lc_align = '';
        break;
      case 'MASTER_LIST_DESCRIPTION':
        $lc_text = TABLE_HEADING_DESCRIPTION;
        $lc_align = 'center';
        break;
      case 'MASTER_LIST_ATTRIBUTES':
        $lc_text = TABLE_HEADING_ATTRIBUTES;
        $lc_align = 'center';
        break;                
      case 'MASTER_LIST_MANUFACTURER':
        $lc_text = TABLE_HEADING_MANUFACTURER;
        $lc_align = '';
        break;
      case 'MASTER_LIST_PRICE':
        $lc_text = TABLE_HEADING_PRICE;
        $lc_align = 'right';
        break;
      case 'MASTER_LIST_QUANTITY':
        $lc_text = TABLE_HEADING_QUANTITY;
        $lc_align = 'right';
        break;
      case 'MASTER_LIST_WEIGHT':
        $lc_text = TABLE_HEADING_WEIGHT;
        $lc_align = 'right';
        break;
      case 'MASTER_LIST_IMAGE':
        $lc_text = TABLE_HEADING_IMAGE;
        $lc_align = 'center';
        break;
      case 'MASTER_LIST_BUY_NOW':
        $lc_text = TABLE_HEADING_BUY_NOW;
        $lc_align = 'center';
        break;
      case 'MASTER_LIST_OPTIONS':
        $lc_text = TABLE_HEADING_OPTIONS;
        $lc_align = 'center';
        break;
    }

    if (($column_list[$col] != 'MASTER_LIST_BUY_NOW') && ($column_list[$col] != 'MASTER_LIST_IMAGE') && ($column_list[$col] != 'MASTER_LIST_MULTIPLE') && ($column_list[$col] != 'MASTER_LIST_DESCRIPTION') && ($column_list[$col] != 'MASTER_LIST_OPTIONS')) {

      $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
    }

    $list_box_contents[0][] = array('align' => $lc_align,
                                    'params' => 'class="productListing-heading"',
                                    'text' => '&nbsp;' . $lc_text . '&nbsp;');
  }

  if ($listing_split->number_of_rows > 0) {
    $rows = 0;
    $master_query = tep_db_query($listing_split->sql_query);
    while ($listing = tep_db_fetch_array($master_query)) {
      $rows++;

      if (($rows/2) == floor($rows/2)) {
        $list_box_contents[] = array('params' => 'class="productListing-even"');
      } else {
        $list_box_contents[] = array('params' => 'class="productListing-odd"');
      }

      $cur_row = sizeof($list_box_contents) - 1;

      for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
        $lc_align = '';
        $lc_params = '';

        switch ($column_list[$col]) {
          case 'MASTER_LIST_MODEL':
            $lc_align = '';
            $lc_text = '&nbsp;' . $listing['products_model'] . '&nbsp;';
            break;
          case 'MASTER_LIST_NAME':
            $lc_align = '';
            if (isset($HTTP_GET_VARS['manufacturers_id'])) {
              $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
            } else {
              $lc_text = '<table cellpadding="0" cellspacing="2"><tr><td>&nbsp;<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>&nbsp;</td></tr></table>';
            }
            break;
          case 'MASTER_LIST_DESCRIPTION':
            $lc_align = '';
            $lc_text = '&nbsp;' . osc_trunc_string(strip_tags($listing['products_description'], '<a><b><em><font><i><s><span><strong><sub><sup><u>'), MASTER_LIST_DESCRIPTION_LENGTH) . '&nbsp;';

            break;            
          case 'MASTER_LIST_MANUFACTURER':
            $lc_align = '';
            $lc_text = '&nbsp;<a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a>&nbsp;';
            break;
          case 'MASTER_LIST_PRICE':
            $lc_align = 'right';
            if (tep_not_null($listing['specials_new_products_price'])) {
              $lc_text = '&nbsp;<s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>&nbsp;';
            } else {
              $lc_text = '&nbsp;' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '&nbsp;';
            }
            break; 
          case 'MASTER_LIST_QUANTITY':
            $lc_align = 'center';
            $lc_text = '&nbsp;' . $listing['products_quantity'] . '&nbsp;';
            break;
          case 'MASTER_LIST_WEIGHT':
            $lc_align = 'right';
            $lc_text = '&nbsp;' . $listing['products_weight'] . '&nbsp;';
            break;
          case 'MASTER_LIST_IMAGE':
            $lc_align = 'center';
            if (isset($HTTP_GET_VARS['manufacturers_id'])) {
              $lc_text = '<table cellpadding="0" cellspacing="2"><tr><td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td></tr></table>';
            } else {
              $lc_text = '<table cellpadding="0" cellspacing="2"><tr><td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td></tr></table>';
            }
            break;
        case 'MASTER_LIST_OPTIONS':
          $lc_align = 'center';
          $lc_text = '';
          ///////////////////////////////////////////////////////////////////////////
          // BOF: attribute options
          $opt_count=0;
          $products_options_name = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . $listing['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");
          while ($products_options_name_values = tep_db_fetch_array($products_options_name)) {
            $opt_count++;
            $products_options_array = array();
            $lc_text .= '<b>' . $products_options_name_values['products_options_name'] . '</b><br />' . "\n";
               $products_options = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$listing['products_id'] . "' and pa.options_id = '" . (int)$products_options_name_values['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");

             while ($products_options_values = tep_db_fetch_array($products_options)) {
               $products_options_array[] = array('id' => $products_options_values['products_options_values_id'], 'text' => $products_options_values['products_options_values_name'], 'style' => '');
               if ($products_options_values['options_values_price'] != '0') {
                 $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options_values['price_prefix'] . $currencies->display_price($products_options_values['options_values_price'], tep_get_tax_rate($product_info_values['products_tax_class_id'])) .') ';
               }
             }
            $lc_text .= tep_draw_pull_down_menu('id_'.$listing['products_id'].'[' . $products_options_name_values['products_options_id'] . ']', $products_options_array);
            $lc_text .= '<br />';
          }
          if($opt_count==0) {
            $lc_text = MASTER_TEXT_NONE;
          }
          // EOF: attribute options
          ///////////////////////////////////////////////////////////////////////////
	   break;
          case 'MASTER_LIST_BUY_NOW': 

            $lc_align = 'center'; 
            $lc_valign = 'top';
            if (tep_get_products_stock($listing['products_id']) < 1) { 
            $lc_text = TEXT_STOCK;
           break;
            } else {
              $quantity = tep_get_products_stock($listing['products_id']);  
              $qty_array = array();
              for ($i=0; $ns = (($quantity < 20) ? $quantity : 20), $i <= $ns; $i++) {
              $qty_array[] = array('id' => $i, 'text' => $i); 
             
              $lc_text = tep_draw_input_field('Qty_ProdId_' . $listing['products_id'], '0', 'size="4" class="inputbox"');
                        
            } 
        }
           break;
/*          case 'MASTER_LIST_BUY_NOW': 
            
	    $lc_align = 'center'; 
            $lc_valign = 'top';
            if ((STOCK_CHECK == 'true')&&(tep_get_products_stock($listing['products_id']) < 1)) { 
            $lc_text = TEXT_STOCK;

          } elseif ((STOCK_CHECK == 'false')&&(tep_get_products_stock($listing['products_id']) < 1)) {
            $qty_array = array();
            for ($i=0; $ns = 20, $i <= $ns; $i++) {
            $qty_array[] = array('id' => $i, 'text' => $i); 
      
	   $lc_text = tep_draw_input_field('Qty_ProdId_' . $listing['products_id'], '0', 'size="4"');
                        
            }
          } else {
           $quantity = tep_get_products_stock($listing['products_id']);
            $qty_array = array();
          for ($i=0; $ns = (($quantity < 20) ? $quantity : 20), $i <= $ns; $i++) {
            $qty_array[] = array('id' => $i, 'text' => $i);
             
	    $lc_text = tep_draw_input_field('Qty_ProdId_' . $listing['products_id'], '0', 'size="4"');
                        
            } 
        }
           break;*/
        }
        $list_box_contents[$cur_row][] = array('align' => $lc_align,
                                               'valign' => $lc_valign,
                                               'params' => 'class="productListing-data"',
                                               'text'  => $lc_text);
      }
    }

    new productListingBox($list_box_contents);
  } else {
    $list_box_contents = array();

    $list_box_contents[0] = array('params' => 'class="productListing-odd"');
    $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                   'text' => TEXT_NO_PRODUCTS);

    new productListingBox($list_box_contents);
  }
?>
     <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
     </table>
<?php
  if ( ($listing_split->number_of_rows > 0) && ((MASTER_PREV_NEXT_BAR_LOCATION == '2') || (MASTER_PREV_NEXT_BAR_LOCATION == '3')) ) {
?>     
     <table border="0" width="100%" cellspacing="0" cellpadding="2">          
     <tr>
        <td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
        <td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
     </tr>
    </table>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>

<?php
  }
?>
</tr>
<tr>
    <td align="center"><table width="100%"><tr>

    <td class="main" align="left"><div class="buttons" style="float: left;"><?php echo '<div class="buttons"><a href="javascript: history.go(-1);">Back</a></div>'; ?></div></td>

      <td align="right" class=""><div class="buttons" style="float: right;"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></div>
	<?php /*echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $product_info['products_id']) . '">' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>';*/ ?>
	</td>
    </tr>
</tbody></table>
<br>
</tr></tbody></table>

